export function request (options = {}) {
  const { url, method = 'GET', onProgress, data = null } = options
  return new Promise((resolve) => {
    const xhr = new XMLHttpRequest()
    xhr.addEventListener('readystatechange', () => {
      if (xhr.readyState === xhr.DONE) {
        resolve(xhr.response)
      }
    })
    xhr.addEventListener('progress', (e) => {
      // 调用 onProgress 并将数据传递给它
      onProgress &&
          onProgress({
            loaded: e.loaded,
            total: e.total
          })
    })
    xhr.open(method, url)
    xhr.responseType = 'arraybuffer'
    xhr.send(data)
  })
}
